package rad.framework.uml2.uml.edit.providers.elementItemProvider.namedElement.packageableElement;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.uml2.uml.InformationFlow;
import org.eclipse.uml2.uml.UMLPackage;

import rad.framework.uml2.uml.edit.UMLEditPlugin;

public class InformationFlowItemProvider
		extends PackageableElementItemProvider
		implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {

	public InformationFlowItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public List getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			addRelatedElementPropertyDescriptor(object);
			addSourcePropertyDescriptor(object);
			addTargetPropertyDescriptor(object);
			addRealizationPropertyDescriptor(object);
			addConveyedPropertyDescriptor(object);
			addInformationSourcePropertyDescriptor(object);
			addInformationTargetPropertyDescriptor(object);
			addRealizingActivityEdgePropertyDescriptor(object);
			addRealizingConnectorPropertyDescriptor(object);
			addRealizingMessagePropertyDescriptor(object);
		}
		return itemPropertyDescriptors;
	}

	protected void addRelatedElementPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_Relationship_relatedElement_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_Relationship_relatedElement_feature", "_UI_Relationship_type"),
				UMLPackage.Literals.RELATIONSHIP__RELATED_ELEMENT, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addSourcePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_DirectedRelationship_source_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_DirectedRelationship_source_feature", "_UI_DirectedRelationship_type"),
				UMLPackage.Literals.DIRECTED_RELATIONSHIP__SOURCE, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addTargetPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_DirectedRelationship_target_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_DirectedRelationship_target_feature", "_UI_DirectedRelationship_type"),
				UMLPackage.Literals.DIRECTED_RELATIONSHIP__TARGET, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addRealizationPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_realization_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_realization_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__REALIZATION, true, null, null, null));
	}

	protected void addConveyedPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_conveyed_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_conveyed_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__CONVEYED, true, null, null, null));
	}

	protected void addInformationSourcePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_informationSource_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_informationSource_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__INFORMATION_SOURCE, true, null, null, null));
	}

	protected void addInformationTargetPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_informationTarget_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_informationTarget_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__INFORMATION_TARGET, true, null, null, null));
	}

	protected void addRealizingActivityEdgePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_realizingActivityEdge_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_realizingActivityEdge_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__REALIZING_ACTIVITY_EDGE, true, null, null, null));
	}

	protected void addRealizingConnectorPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_realizingConnector_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_realizingConnector_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__REALIZING_CONNECTOR, true, null, null, null));
	}

	protected void addRealizingMessagePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_InformationFlow_realizingMessage_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_InformationFlow_realizingMessage_feature", "_UI_InformationFlow_type"),
				UMLPackage.Literals.INFORMATION_FLOW__REALIZING_MESSAGE, true, null, null, null));
	}

	@Override
	public Object getImage(Object object) {
		return overlayImage(object, getResourceLocator().getImage("full/obj16/InformationFlow"));
	}

	@Override
	public String getText(Object object) {
		final String label = ((InformationFlow) object).getName();
		return label == null || label.length() == 0 ? getString("_UI_InformationFlow_type") :
				getString("_UI_InformationFlow_type") + " " + label;
	}

	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);
		super.notifyChanged(notification);
	}

	@Override
	protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
	}

	@Override
	public ResourceLocator getResourceLocator() {
		return UMLEditPlugin.INSTANCE;
	}

}
